import Cookie from "js-cookie";
import {shoppingcart} from "../../http/api"

const userInfo = {
    state: {
        regid: Cookie.get("regid"),
        username: Cookie.get("username"),
        shopnum:0
    },
    mutations: {
        serUerInfo(state, params) {
            state.regid = params.regid;
            state.username = params.username;
            Cookie.set("username", params.username);
            Cookie.set("regid", params.regid);
        },
        clearInfo(state) {
            state.regid = null;
            state.username = "";
        },
        shopcar(state) {
            if(state.regid){
                shoppingcart().then(res=>{
                    state.shopnum = res.data.productCount
                })
            }
            
        }
    }
};
export default userInfo;
